package com.msg.xml;

import java.util.HashMap;

/**
 * It is a class that providing the insertion and accessing of data in Ticket Group Prediction
 * @author jeson9603
 *
 */
public class GroupPrediction_Manipulator extends Table_Manipulator {

	//prediction id for a ticket group type
	private String predictionId_m = null;
	//ticket group name
	private String groupName_m = null;
	
	public GroupPrediction_Manipulator(Property prop) {
		super(prop);
	}
	
	@Override
	protected String getSpecificData() {
		return null;
	}

	/**
	 * adding new ticket group prediction data row in the {@code Ticket_Group_Prediction table}
	 */
	@Override
	protected String update() {
		DBRequest request = new DBRequest();
		request.resultCol.add("Ticket_Group_Prediction_Id");
		request.entries.add("Ticket_Group_Prediction_Id");
		request.data.add(predictionId_m);
		if(!DBhandler.hasData("ticket_group_prediction", request)) {
			if(groupName_m != null) {
				request.entries.add("Ticket_Group_Name");
				request.data.add(groupName_m);
			}
			DBhandler.insertData("ticket_group_prediction", request);
		}
		return predictionId_m;
	}

	/**
	 * interpreting the hash map passed by {@code TicketGroup_Manipulator}, saving the information
	 * of {@code Ticket_Group_Prediction_Id} and {@code Ticket_Group_Name}
	 * {@code Ticket_Group_Name} may be null if the {@code TicketGroup_Manipulator} is 8
	 */
	@Override
	protected void pushData(Object o) {
		@SuppressWarnings("unchecked")
		HashMap<String, String> predictionMap = (HashMap<String, String>)o;
		predictionId_m = predictionMap.get("Ticket_Group_Prediction_Id");
		if(predictionMap.containsKey("Ticket_Group_Name"))
			groupName_m = predictionMap.get("Ticket_Group_Name");
	}

}
